package com.omenkk.juc.synchronizedPlus;

import com.omenkk.juc.util.Slepper;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class demo8 {
    public static void main(String[] args) {
        Object o1=new Object();
        Object o2=new Object();
        Thread t1=new Thread(()->{
            synchronized (o1){
                log.debug("t1获得锁o1");
                Slepper.sleep(1);
                synchronized (o2){
                    log.debug("t1获得锁o2");
                    log.debug("t1开始操作");
                }
            }
        });
        Thread t2=new Thread(()->{
            synchronized (o2){
                log.debug("t2获得锁o2");
                Slepper.sleep(1);
                synchronized (o1){
                    log.debug("t2获得锁o1");
                    log.debug("t2开始操作");
                }
            }
        });
        t1.start();
        t2.start();

    }
}
